﻿using System.ComponentModel;

namespace Futuret.Core.Futuret;

/// <summary>
///     Author: Riva
///     Date: 2023/7/11 14:50
///     Description:
/// </summary>
public class UnifyResponse : IResult<object>
{
    /// <summary>
    ///     返回码
    /// </summary>
    public CodeEnum code { get; set; }

    /// <summary>
    ///     数据源
    /// </summary>
    public object? data { get; set; }

    /// <summary>
    ///     信息
    /// </summary>
    public string? msg { get; set; }

    /// <summary>
    ///     是否成功
    /// </summary>
    public bool success => CodeEnum.Success == code;

    /// <summary>
    ///     时间戳
    /// </summary>
    public long time => DateTimeOffset.UtcNow.ToUnixTimeSeconds();
}

/// <summary>
///     统一返回
/// </summary>
public interface IResult
{
    string? msg { get; set; }
    bool success { get; }
    long time { get; }
    CodeEnum code { get; set; }
}

public interface IResult<out T> : IResult
{
    T? data { get; }
}

public enum CodeEnum
{
    /// <summary>
    /// </summary>
    [Description("成功")] Success = 200,

    /// <summary>
    /// </summary>
    [Description("未授权")] Unauthorized = 401,

    /// <summary>
    /// </summary>
    [Description("无权访问")] AccessDenied = 400,

    /// <summary>
    /// </summary>
    [Description("禁止相应")] ProhibitCorresponding = 403,

    /// <summary>
    /// </summary>
    [Description("失败")] Error = 500
}